package com.jzrh.flashbee.common.utils;

import java.time.Instant;

/**
 * @author Jince
 * @since: 2023.11.22 下午 09:00
 * @description: 编码
 */
public class GenerateUtil {
    private static final String CHAR_SET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    public static String generateShortLink() {
        long timestamp = Instant.now().getEpochSecond();
        StringBuilder shortCodeBuilder = new StringBuilder();
        while (timestamp > 0) {
            int remainder = (int) (timestamp % CHAR_SET.length());
            shortCodeBuilder.insert(0, CHAR_SET.charAt(remainder));
            timestamp = timestamp / CHAR_SET.length();
        }
        return shortCodeBuilder.toString();
    }
}
